<template>
    <div class="course-reach">
        <div class="box">
            <div class="btn-area">
                <el-button
                    class="flex-r"
                    type="primary"
                    icon="el-icon-circle-plus-outline"
                    @click="openDialog(1)"
                >
                    添加达成度
                </el-button>
            </div>
            <div class="list">
                <ul v-if="list.length">
                    <router-link v-for="(item,index) in list" :key="item.id" tag="li" :to="{ name: 'CourseReachInfo', params: { id: item.id }}">
                        <div class="item-box">
                            <div
                                class="left"
                            >
                                <div :class="'icon' + item.iconValue">
                                    <img :src="'/../../../static/images/' + item.iconValue + '.png'">
                                </div>
                            </div>
                            <div class="right">
                                <el-tooltip v-if="item.name.length > 12" class="item" effect="dark" :content="item.name" placement="top">
                                    <div class="title">{{ item.name }}</div>
                                </el-tooltip>
                                <div v-else class="title">{{ item.name }}</div>
                                <div class="student-num">学生人数：{{ item.studentCount }}人</div>
                                <div class="person">负责人：{{ item.principal }}</div>
                            </div>

                            <span class="copy" @click.stop="openDialog(2, item)">
                                <el-tooltip
                                    class="item"
                                    effect="dark"
                                    placement="bottom-start"
                                >
                                    <div slot="content">注：点击复制按钮，可复制当前达成度统计的课程目标信息，考核项信息。<br/>不复制学生信息、成绩信息、统计信息。</div>
                                    <i class="el-icon-document-copy"></i>
                                </el-tooltip>

                            </span>
                            <span class="remove" @click.stop="remove(index, item.id)">
                                <i class="el-icon-delete"></i>
                            </span>
                        </div>
                    </router-link>
                </ul>
                <div v-else class="no-source">
                    <img src='../../../../assets/images/empty.png'/>
                    <p>暂无课程达成度</p>
                </div>
            </div>
        </div>
        <setDialog @refresh="refresh" ref="setDialog" />

        <tipsDialog
            ref="tipsDialog"
            @sure="callBack"
        />
    </div>
</template>
<script>
import tipsDialog from '../../../../components/tipsDialog';
import { courseReachList, delCourseReach } from '../../../../api/courseReach';
import setDialog from './component/dialog';
export default {
    components: {
        setDialog,
        tipsDialog
    },
    data() {
        return {
            list: [],
            removeId: null,
            removeIndex: null
        }
    },
    created() {
        this.courseId = localStorage.getItem('setCourseId');
        this.init(this.courseId);
    },
    methods: {
        init(courseId) {
            courseReachList({ courseId }).then((res) => {
                const { data } = res;
                this.list = data;
                localStorage.setItem('REACHLIST', JSON.stringify(data,['id', 'name']));
            })
        },

        openDialog(type, item) {
            this.$refs.setDialog.init(type, item, this.courseId);
        },

        refresh() {
            this.init(this.courseId);
        },

        remove(index, id) {
            this.removeIndex = index;
            this.removeId = id;
            this.$refs.tipsDialog.init({
                type: 'error',
                info: '是否删除选中'
            });

        },

        callBack() {
            delCourseReach({ id: this.removeId }).then(res => {
                this.list.splice(this.removeIndex,1);
                localStorage.setItem('REACHLIST', JSON.stringify(this.list,['id', 'name']));
            });
        }
    }
}
</script>
<style lang="scss">
.course-reach {
    .icon1,.icon2,.icon3 {
        img {
            width: 52px;
        }
    }

    .icon1 {
        background: #5C75DA;
    }

    .icon2 {
        background: #FE806D;
    }

    .icon3 {
        background: #36CAC6;
    }

    .el-icon-circle-plus-outline {
        font-size: 16px;
        vertical-align: inherit;
    }

    .btn-area {
        span {
            vertical-align: middle;
        }
    }
}

</style>
<style lang="scss" scoped>
.course-reach {
    width: 1200px;
    margin: 0 auto;
    .box {
        background: #fff;
        border-radius: 0 0 5px 5px;
        box-shadow: 0 0 10px rgba(0,0,0,0.05);
        padding-top: 20px;
        .btn-area {
            overflow: hidden;
        }
        .flex-r {
            margin-right: 40px;
            float: right;
        }
        .list {
            margin-top: 15px;
            ul {
                padding: 0 30px 115px;
            }
            li {
                overflow: hidden;
                display: inline-block;
                width: 360px;
                height: 130px;
                background: #FFFFFF;
                box-shadow: 0px 6px 32px 0px rgba(0, 0, 0, 0.2);
                border-radius: 5px;
                margin: 15px 8px;
                cursor: pointer;
                transition: all 0.3s;
                &:hover {
                    transform: translateY(-10px);
                    box-shadow: 0px 6px 40px 0px rgba(0, 0, 0, 0.2);
                    .copy,.remove {
                        display: block;
                    }
                }

            }

            .item-box {
                display: flex;
                height: 100%;
                align-items: center;
                position: relative;
                .left {
                    width: 110px;
                    height: 100%;
                    text-align: center;
                    line-height: 130px;
                    flex-shrink: 0;
                }

                .right {
                    position: relative;
                    flex: 1;
                    margin-left: 20px;
                    .title {
                        color: #3A3A3A;
                        font-size: 18px;
                        font-weight: 400;
                        margin-bottom: 22px;
                        word-break: break-word;
                        white-space: nowrap;
                        word-wrap: break-word;
                        text-overflow: ellipsis;
                        width: 210px;
                        overflow: hidden;
                    }

                    .student-num,.person {
                        font-size: 14px;
                        font-weight: 400;
                    }

                    .person {
                        margin-top: 10px;
                    }

                }

                .copy,.remove {
                    display: none;
                    position: absolute;
                    height: 18px;
                    width: 18px;
                    bottom: 10px;
                    &:hover {
                        i {
                            color: #1277eb;
                        }
                    }
                    i {
                        font-size: 18px;
                        color: #0f5576;
                    }


                }

                .remove {
                    right: 10px;
                }

                .copy {
                    right: 38px;
                }


            }

            .no-source {
                text-align: center;
                padding: 100px 0;
                p {
                    margin-top: 15px;
                }
            }
        }
    }
}
</style>
